package c.e.a.b.e.c;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;

/* compiled from: com.google.android.gms:play-services-measurement-base@@18.0.0 */
public class t6<K extends Comparable<K>, V> extends AbstractMap<K, V> {
    public static final /* synthetic */ int g = 0;
    public final int a;
    public List<a7> b = Collections.emptyList();
    public Map<K, V> c = Collections.emptyMap();
    public boolean d;
    public volatile c7 e;
    public Map<K, V> f = Collections.emptyMap();

    public t6(int i, v6 v6Var) {
        this.a = i;
    }

    public final int a(K k) {
        int compareTo;
        int size = this.b.size() - 1;
        if (size >= 0) {
            compareTo = k.compareTo(((a7) this.b.get(size)).a);
            if (compareTo > 0) {
                return -(size + 2);
            }
            if (compareTo == 0) {
                return size;
            }
        }
        compareTo = 0;
        while (compareTo <= size) {
            int i = (compareTo + size) / 2;
            int compareTo2 = k.compareTo(((a7) this.b.get(i)).a);
            if (compareTo2 < 0) {
                size = i - 1;
            } else if (compareTo2 <= 0) {
                return i;
            } else {
                compareTo = i + 1;
            }
        }
        return -(compareTo + 1);
    }

    /* renamed from: b */
    public final V put(K k, V v) {
        h();
        int a = a(k);
        if (a >= 0) {
            a7 a7Var = (a7) this.b.get(a);
            a7Var.c.h();
            Object obj = a7Var.b;
            a7Var.b = v;
            return obj;
        }
        h();
        if (this.b.isEmpty() && !(this.b instanceof ArrayList)) {
            this.b = new ArrayList(this.a);
        }
        a = -(a + 1);
        if (a >= this.a) {
            return i().put(k, v);
        }
        int size = this.b.size();
        int i = this.a;
        if (size == i) {
            a7 a7Var2 = (a7) this.b.remove(i - 1);
            i().put(a7Var2.a, a7Var2.b);
        }
        this.b.add(a, new a7(this, k, v));
        return null;
    }

    public void c() {
        if (!this.d) {
            Map emptyMap;
            if (this.c.isEmpty()) {
                emptyMap = Collections.emptyMap();
            } else {
                emptyMap = Collections.unmodifiableMap(this.c);
            }
            this.c = emptyMap;
            if (this.f.isEmpty()) {
                emptyMap = Collections.emptyMap();
            } else {
                emptyMap = Collections.unmodifiableMap(this.f);
            }
            this.f = emptyMap;
            this.d = true;
        }
    }

    public void clear() {
        h();
        if (!this.b.isEmpty()) {
            this.b.clear();
        }
        if (!this.c.isEmpty()) {
            this.c.clear();
        }
    }

    public boolean containsKey(Object obj) {
        Comparable comparable = (Comparable) obj;
        return a(comparable) >= 0 || this.c.containsKey(comparable);
    }

    public final Entry<K, V> d(int i) {
        return (Entry) this.b.get(i);
    }

    public final int e() {
        return this.b.size();
    }

    public Set<Entry<K, V>> entrySet() {
        if (this.e == null) {
            this.e = new c7(this, null);
        }
        return this.e;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof t6)) {
            return super.equals(obj);
        }
        t6 t6Var = (t6) obj;
        int size = size();
        if (size != t6Var.size()) {
            return false;
        }
        int e = e();
        if (e != t6Var.e()) {
            return entrySet().equals(t6Var.entrySet());
        }
        for (int i = 0; i < e; i++) {
            if (!d(i).equals(t6Var.d(i))) {
                return false;
            }
        }
        if (e != size) {
            return this.c.equals(t6Var.c);
        }
        return true;
    }

    public final V f(int i) {
        h();
        Object obj = ((a7) this.b.remove(i)).b;
        if (!this.c.isEmpty()) {
            Iterator it = i().entrySet().iterator();
            this.b.add(new a7(this, (Entry) it.next()));
            it.remove();
        }
        return obj;
    }

    public final Iterable<Entry<K, V>> g() {
        if (this.c.isEmpty()) {
            return w6.b;
        }
        return this.c.entrySet();
    }

    public V get(Object obj) {
        Comparable comparable = (Comparable) obj;
        int a = a(comparable);
        if (a >= 0) {
            return ((a7) this.b.get(a)).b;
        }
        return this.c.get(comparable);
    }

    public final void h() {
        if (this.d) {
            throw new UnsupportedOperationException();
        }
    }

    public int hashCode() {
        int i = 0;
        for (int i2 = 0; i2 < e(); i2++) {
            i += ((a7) this.b.get(i2)).hashCode();
        }
        return this.c.size() > 0 ? i + this.c.hashCode() : i;
    }

    public final SortedMap<K, V> i() {
        h();
        if (this.c.isEmpty() && !(this.c instanceof TreeMap)) {
            TreeMap treeMap = new TreeMap();
            this.c = treeMap;
            this.f = treeMap.descendingMap();
        }
        return (SortedMap) this.c;
    }

    public V remove(Object obj) {
        h();
        Comparable comparable = (Comparable) obj;
        int a = a(comparable);
        if (a >= 0) {
            return f(a);
        }
        if (this.c.isEmpty()) {
            return null;
        }
        return this.c.remove(comparable);
    }

    public int size() {
        return this.c.size() + this.b.size();
    }
}
